package com.example.xm503xk.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

import com.example.xm503xk.R;
import com.example.xm503xk.bean.userBean;
import com.example.xm503xk.iface.LoginListener;

public class LoginActivity extends AppCompatActivity  implements LoginListener{
    private Button user_login_button,user_register_button0;
    private EditText login_username1,login_password1;
    private Context context;
    private CheckBox mRememberCheck;
    private SharedPreferences login_sp;
    public int pwdresetFlag=0;
    private EditText mAccount;                        //用户名编辑
    private EditText mPwd;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        context = LoginActivity.this;
        user_register_button0 = (Button) findViewById(R.id.user_register_button);
        user_login_button = (Button) findViewById(R.id.user_login_button);
       mRememberCheck = (CheckBox) findViewById(R.id.Login_Remember);
        login_username1=(EditText)findViewById(R.id.login_username1);  //获取用户名
        login_password1=(EditText)findViewById(R.id.login_password1);  //获取密码

        //按钮监听
        user_register_button0.setOnClickListener(login_Lister);
        user_login_button.setOnClickListener(login_Lister);
        login_sp = getSharedPreferences("userInfo", 0);
       String name=login_sp.getString("USER_NAME", "");
       String pwd =login_sp.getString("PASSWORD", "");
      boolean choseRemember =login_sp.getBoolean("mRememberCheck", false);
       boolean choseAutoLogin =login_sp.getBoolean("mAutologinCheck", false);
        //如果上次选了记住密码，那进入登录页面也自动勾选记住密码，并填上用户名和密码
       if(choseRemember){
            mAccount.setText(name);
            mPwd.setText(pwd);
            mRememberCheck.setChecked(true);
        }

    }
    View.OnClickListener login_Lister=new View.OnClickListener(){

        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.user_register_button:
                    //返回注册   代码实现
                    registered();
                    break;
                case R.id.user_login_button:
                    //登录实现  代码
                    login_check();
                    break;
            }
        }
    };
    public  void registered(){
        Intent intent_registered=new Intent(LoginActivity.this, registeredActivity.class );
        startActivity (intent_registered );
    }
    public void login_su(){
        Intent intent_login_su=new Intent(LoginActivity.this, mainActivity.class );
        startActivity (intent_login_su );
    }
    public  void login_check(){


        login_su();
    }
    @Override
    public void onResponse(userBean userBean) {

    }

    @Override
    public void onFail(String msg) {

    }
}
